home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxfmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.0 KB  |  110 lines

  1. /* Copyright (C) 1992, 1995, 1996, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxfmap.h,v 1.3 2000/09/19 19:00:37 lpd Exp $ */
  20. /* Fraction map representation for Ghostscript */
  21.  
  22. #ifndef gxfmap_INCLUDED
  23. #  define gxfmap_INCLUDED
  24.  
  25. #include "gsrefct.h"
  26. #include "gsstype.h"
  27. #include "gxfrac.h"
  28. #include "gxtmap.h"
  29.  
  30. /*
  31.  * Define a cached map from fracs to fracs.  Level 1 uses this only
  32.  * for the transfer function; level 2 also uses it for black generation
  33.  * and undercolor removal.  Note that reference counting macros must
  34.  * be used to allocate, free, and assign references to gx_transfer_maps.
  35.  *
  36.  * NOTE: proc and closure are redundant.  Eventually closure will replace
  37.  * proc.  For now, things are in an uneasy intermediate state where
  38.  * proc = 0 means use closure.
  39.  */
  40. /* log2... must not be greater than frac_bits, and must be least 8. */
  41. #define log2_transfer_map_size 8
  42. #define transfer_map_size (1 << log2_transfer_map_size)
  43. /*typedef struct gx_transfer_map_s gx_transfer_map; *//* in gxtmap.h */
  44. struct gx_transfer_map_s {
  45.     rc_header rc;
  46.     gs_mapping_proc proc;    /* typedef is in gxtmap.h */
  47.     gs_mapping_closure_t closure;    /* SEE ABOVE */
  48.     /* The id changes whenever the map or function changes. */
  49.     gs_id id;
  50.     frac values[transfer_map_size];
  51. };
  52.  
  53. extern_st(st_transfer_map);
  54. #define public_st_transfer_map() /* in gscolor.c */\
  55.   gs_public_st_composite(st_transfer_map, gx_transfer_map, "gx_transfer_map",\
  56.     transfer_map_enum_ptrs, transfer_map_reloc_ptrs)
  57.  
  58. /* Set a transfer map to the identity map. */
  59. void gx_set_identity_transfer(P1(gx_transfer_map *));
  60.  
  61. /*
  62.  * Map a color fraction through a transfer map.  If the map is small,
  63.  * we interpolate; if it is large, we don't, and save a lot of time.
  64.  */
  65. #define FRAC_MAP_INTERPOLATE (log2_transfer_map_size <= 8)
  66. #if FRAC_MAP_INTERPOLATE
  67.  
  68. frac gx_color_frac_map(P2(frac, const frac *));        /* in gxcmap.c */
  69.  
  70. #  define gx_map_color_frac(pgs,cf,m)\
  71.      (pgs->m->proc == gs_identity_transfer ? cf :\
  72.       gx_color_frac_map(cf, &pgs->m->values[0]))
  73.  
  74. #else /* !FRAC_MAP_INTERPOLATE */
  75.  
  76. /* Do the lookup in-line. */
  77. #  define gx_map_color_frac(pgs,cf,m)\
  78.      (pgs->m->values[frac2bits(cf, log2_transfer_map_size)])
  79.  
  80. #endif /* (!)FRAC_MAP_INTERPOLATE */
  81.  
  82. /* Map a color fraction expressed as a byte through a transfer map. */
  83. /* (We don't use this anywhere right now.) */
  84. /****************
  85. #if log2_transfer_map_size <= 8
  86. #  define byte_to_tmx(b) ((b) >> (8 - log2_transfer_map_size))
  87. #else
  88. #  define byte_to_tmx(b)\
  89.     (((b) << (log2_transfer_map_size - 8)) +\
  90.      ((b) >> (16 - log2_transfer_map_size)))
  91. #endif
  92. #define gx_map_color_frac_byte(pgs,b,m)\
  93.  (pgs->m->values[byte_to_tmx(b)])
  94.  ****************/
  95.  
  96. /* Map a floating point value through a transfer map. */
  97. #define gx_map_color_float(pmap,v)\
  98.   ((pmap)->values[(int)((v) * transfer_map_size + 0.5)] / frac_1_float)
  99.  
  100. /* Define a mapping procedure that just looks up the value in the cache. */
  101. /* (It is equivalent to gx_map_color_float with the arguments swapped.) */
  102. float gs_mapped_transfer(P2(floatp, const gx_transfer_map *));
  103.  
  104. /* Define an identity mapping procedure. */
  105. /* Don't store this directly in proc/closure.proc: */
  106. /* use gx_set_identity_transfer. */
  107. float gs_identity_transfer(P2(floatp, const gx_transfer_map *));
  108.  
  109. #endif /* gxfmap_INCLUDED */
  110.